package com.ruoyi.report.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.report.domain.ReportTablebaseColumn;
import com.ruoyi.report.mapper.ReportTablebaseColumnMapper;
import com.ruoyi.report.service.IReportTablebaseColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 表格列数据Service业务层处理
 * 
 * @author wry
 * @date 2023-06-20
 */
@Service
public class ReportTablebaseColumnServiceImpl implements IReportTablebaseColumnService 
{
    @Autowired
    private ReportTablebaseColumnMapper reportTablebaseColumnMapper;

    /**
     * 查询表格列数据
     * 
     * @param columnId 表格列数据主键
     * @return 表格列数据
     */
    @Override
    public ReportTablebaseColumn selectReportTablebaseColumnByColumnId(Long columnId)
    {
        return reportTablebaseColumnMapper.selectReportTablebaseColumnByColumnId(columnId);
    }

    /**
     * 查询表格列数据列表
     * 
     * @param reportTablebaseColumn 表格列数据
     * @return 表格列数据
     */
    @Override
    public List<ReportTablebaseColumn> selectReportTablebaseColumnList(ReportTablebaseColumn reportTablebaseColumn)
    {
        return reportTablebaseColumnMapper.selectReportTablebaseColumnList(reportTablebaseColumn);
    }
    public List<ReportTablebaseColumn> selectReportTableBaseColumnAllByTableId(Long tableId){
        return reportTablebaseColumnMapper.selectReportTableBaseColumnAllByTableId(tableId);
    }
    /**
     * 新增表格列数据
     * 
     * @param reportTablebaseColumn 表格列数据
     * @return 结果
     */
    @Override
    public int insertReportTablebaseColumn(ReportTablebaseColumn reportTablebaseColumn)
    {
        reportTablebaseColumn.setCreateTime(DateUtils.getNowDate());
        return reportTablebaseColumnMapper.insertReportTablebaseColumn(reportTablebaseColumn);
    }

    /**
     * 修改表格列数据
     * 
     * @param reportTablebaseColumn 表格列数据
     * @return 结果
     */
    @Override
    public int updateReportTablebaseColumn(ReportTablebaseColumn reportTablebaseColumn)
    {
        reportTablebaseColumn.setUpdateTime(DateUtils.getNowDate());
        return reportTablebaseColumnMapper.updateReportTablebaseColumn(reportTablebaseColumn);
    }

    /**
     * 批量删除表格列数据
     * 
     * @param columnIds 需要删除的表格列数据主键
     * @return 结果
     */
    @Override
    public int deleteReportTablebaseColumnByColumnIds(Long[] columnIds)
    {
        return reportTablebaseColumnMapper.deleteReportTablebaseColumnByColumnIds(columnIds);
    }

    /**
     * 删除表格列数据信息
     * 
     * @param columnId 表格列数据主键
     * @return 结果
     */
    @Override
    public int deleteReportTablebaseColumnByColumnId(Long columnId)
    {
        return reportTablebaseColumnMapper.deleteReportTablebaseColumnByColumnId(columnId);
    }

    /**
     * 校验字典类型称是否唯一
     *
     * @param reportTablebaseColumn 表格数据
     * @return 结果
     */
    @Override
    public boolean checkReportColumnUnique(ReportTablebaseColumn reportTablebaseColumn)
    {
        Long columnId = StringUtils.isNull(reportTablebaseColumn.getColumnId()) ? -1L : reportTablebaseColumn.getColumnId();
        ReportTablebaseColumn column = reportTablebaseColumnMapper.checkReportColumnUnique(reportTablebaseColumn.getColumnName());
        if (StringUtils.isNotNull(column) && column.getColumnId().longValue() != columnId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
